package com.liu.adapter;

import java.util.List;

import com.liu.crypto.Aes;
import com.liu.keeppwd.SysState;
import com.liu.model.Pwd;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class PwdAdapter extends BaseAdapter {
	List<Pwd> lst;
	Context content;

	public PwdAdapter(List<Pwd> lst, Context content) {
		this.lst = lst;
		this.content = content;
	}

	@Override
	public int getCount() {
		return lst.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@SuppressLint("SimpleDateFormat")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LinearLayout ll = new LinearLayout(content);
		ll.setOrientation(LinearLayout.HORIZONTAL);

		TextView tv = new TextView(content);
		TextView tv0 = new TextView(content);
		tv0.setWidth(SysState.dp2pix(content, 90));

		int w = SysState.getPwidth((Activity) content)
				- SysState.dp2pix(content, 90);
		tv.setWidth(w);

		tv0.setGravity(Gravity.CENTER);
		tv.setTextColor(Color.rgb(255, 255, 255));
		tv0.setTextColor(Color.rgb(255, 255, 255));
		Pwd pd = lst.get(position);
		try {
			String mm = Aes.Decrypt(SysState.mainKey + pd.getEcmy(),
					pd.getPwd());
			tv.setText(mm);
		} catch (Exception e) {
		}
		java.text.DateFormat format2 = new java.text.SimpleDateFormat(
				"yyyy-MM-dd\r\nHH:mm:ss");
		tv0.setText(format2.format(pd.getCreateTime()));
		ll.addView(tv);
		ll.addView(tv0);

		return ll;
	}
}
